var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all) __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if ((from && typeof from === 'object') || typeof from === 'function') {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, {
          get: () => from[key],
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
        });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (
  (target = mod != null ? __create(__getProtoOf(mod)) : {}),
  __copyProps(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    isNodeMode || !mod || !mod.__esModule
      ? __defProp(target, 'default', { value: mod, enumerable: true })
      : target,
    mod,
  )
);
var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: true }), mod);

// src/DatePicker/QuickRangePicker/index.tsx
var QuickRangePicker_exports = {};
__export(QuickRangePicker_exports, {
  default: () => QuickRangePicker_default,
});
module.exports = __toCommonJS(QuickRangePicker_exports);
var import_react = __toESM(require('react'));
var import_classnames = __toESM(require('classnames'));
var import_dayjs = __toESM(require('dayjs'));
var import_antd = require('antd');
var import_style = require('antd/es/date-picker/style/index.js');
var import_style2 = require('antd/es/select/style/index.js');
var import_createField = __toESM(require('../../createField'));
var import_consts = require('./consts');
var import_index = require('./index.less');
function QuickRangePicker({
  type = ['now', 'day', 'week', 'month'],
  value: valueProp,
  onChange,
  startDay,
  className,
  selectProps,
  ...rest
}) {
  var _a;
  const [value, setValue] = (0, import_react.useState)();
  (0, import_react.useEffect)(() => {
    if (type.length && !valueProp && !value) {
      const newValue = { type: type == null ? void 0 : type[0] };
      setValue(newValue);
      onChange == null ? void 0 : onChange(newValue);
    }
  }, [type]);
  (0, import_react.useEffect)(() => {
    if (valueProp && valueProp !== value) {
      setValue(valueProp);
    }
  }, [valueProp]);
  const typeOptions = (0, import_react.useMemo)(
    () =>
      type == null
        ? void 0
        : type.map((it) => {
            return {
              value: it,
              label: import_consts.TypeTexts[it],
              picker: ['now', 'day'].includes(it) ? 'date' : it,
            };
          }),
    [type],
  );
  const onSelectChange = (0, import_react.useCallback)(
    (type2) => {
      const newValue = {
        ...value,
        type: type2,
      };
      setValue(newValue);
      onChange == null ? void 0 : onChange(newValue);
    },
    [value, onChange],
  );
  const onDatePickerChange = (0, import_react.useCallback)(
    (date) => {
      const newValue = {
        ...value,
        date,
      };
      setValue(newValue);
      onChange == null ? void 0 : onChange(newValue);
    },
    [value, onChange],
  );
  return /* @__PURE__ */ import_react.default.createElement(
    'div',
    {
      style: { display: 'flex' },
      className: (0, import_classnames.default)('szzj-quick-range-picker', className),
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Select, {
      placeholder: '请选择维度',
      options: typeOptions,
      style: { width: 160, marginRight: 10 },
      ...selectProps,
      value: value == null ? void 0 : value.type,
      onChange: onSelectChange,
    }),
    (value == null ? void 0 : value.type) &&
      /* @__PURE__ */ import_react.default.createElement(import_antd.DatePicker, {
        placeholder: `请选择${
          (value == null ? void 0 : value.type) === 'now'
            ? '日期'
            : import_consts.TypeTexts[value == null ? void 0 : value.type]
        }`,
        disabledDate: (curr) => {
          return startDay
            ? // @ts-ignore
              curr.isBefore(startDay) || curr.isAfter((0, import_dayjs.default)())
            : // @ts-ignore
              curr.isAfter((0, import_dayjs.default)());
        },
        ...rest,
        picker:
          (_a =
            typeOptions == null
              ? void 0
              : typeOptions.find((it) => it.value === (value == null ? void 0 : value.type))) ==
          null
            ? void 0
            : _a.picker,
        value: value == null ? void 0 : value.date,
        onChange: onDatePickerChange,
      }),
  );
}
var FormatMap = {
  date: 'YYYY-MM-DD',
  year: 'YYYY',
  quarter: 'YYYY-\\QQ',
  month: 'YYYY-MM',
  week: 'YYYY-wo',
};
var QuickRangePicker_default = (0, import_createField.default)(QuickRangePicker, {
  defaultDetailComponent: function QuickRangePickerDetail({ value }) {
    var _a;
    const picker = ['now', 'day'].includes(value == null ? void 0 : value.type)
      ? 'date'
      : value == null
      ? void 0
      : value.type;
    const format = FormatMap[picker];
    return (value == null ? void 0 : value.type)
      ? /* @__PURE__ */ import_react.default.createElement(
          'div',
          null,
          `${import_consts.TypeTexts[value == null ? void 0 : value.type]}：${
            ((_a = value == null ? void 0 : value.date) == null ? void 0 : _a.format(format)) ?? ''
          }`,
        )
      : null;
  },
});
